

### This file contains code for the appendices that do not include
### main analyses and regressions for robustness checks. It requires
### the output from the script "Main analyses".

library(data.table)
library(tidyverse)

##### Supplementary Appendix D: descriptive statistics #####

### Figure D1

## new data frame for plotting
descrH1 <- cbind(rbind(data.frame(extra = data1$extra),
                       data.frame(extra = data2$extra)),
                 rbind(data.frame(agree = data1$agree),
                       data.frame(agree = data2$agree)),
                 rbind(data.frame(polact1 = data1$polact1),
                       data.frame(polact1 = data2$navact)),
                 rbind(data.frame(polact2 = data1$polact2),
                       data.frame(polact2 = data2$navact)),
                 rbind(data.frame(putin_sup = data1$putin_sup),
                       data.frame(putin_sup = rep(0, length(data2$extra)))),
                 sample = factor(c(rep("2013 survey", length(data1$extra)),
                                   rep("2018 Navalny survey", length(data2$extra)))))
descrH1$pooled <- "pooled 2013 survey and 2018 Navalny survey"

# prepare plotting
descrH1$sample <- factor(descrH1$sample, levels = c("2013 survey", "2018 Navalny survey"))
descrH1$polact1 <- factor(descrH1$polact1, levels = c("1", "0"))
descrH1$putin_sup <- factor(descrH1$putin_sup, levels = c("1", "0"))

# plot extraversion for H1
p.descrH1 <- ggplot(descrH1[!is.na(descrH1$polact1),], aes(x = factor(polact1), y = extra,
                                                       fill = factor(sample))) +
  geom_violin(adjust = 1.3,
              kernel = "g") +
  stat_summary(fun = mean, geom = "errorbar", aes(ymax = ..y.., ymin = ..y..),
               width = 1, linetype = "solid") +
  scale_x_discrete(breaks = c("1", "0"),
                   labels = c("active", "not active")) +
  facet_wrap(~ factor(sample)) +
  scale_fill_manual(name="Sample",
                    breaks=c("2013 survey", "2018 Navalny survey"),
                    labels=c("2013 survey", "2018 Navalny survey"),
                    values = c("grey90", "grey60")) +
  xlab("") +
  ylab("extraversion") +
  theme_bw() +
  theme(legend.position = "none"); p.descrH1
ggsave("Figure_D1a.pdf", gridExtra::grid.arrange(p.descrH1, top = "extraversion in both samples"),
       width = 8, height = 4)

## plot both for H3 in 2013 survey
descrH1$subset <- ifelse(descrH1$polact1==0 & descrH1$putin_sup==1 & descrH1$sample=="2013 survey",0,
                        ifelse(descrH1$polact1==1 & descrH1$putin_sup==0 & descrH1$sample=="2013 survey",1,NA))

# extra
p.H3desc_ex <- ggplot(descrH1[!is.na(descrH1$subset),], aes(x = factor(subset), y = extra,
                                                          fill = factor(sample))) +
  geom_violin(adjust = 1.3) +
  stat_summary(fun = mean, geom = "errorbar", aes(ymax = ..y.., ymin = ..y..),
               width = 1, linetype = "solid") +
  scale_x_discrete(breaks = c("1", "0"),
                   labels = c("active\nPutin opponents", 
                              "non-active\nPutin supporters")) +
  scale_fill_manual(values = c("grey90")) +
  xlab("") +
  ylab("extraversion") +
  theme_bw() +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5)); p.H3desc_ex

# agree
p.H3desc_ag <- ggplot(descrH1[!is.na(descrH1$subset),], aes(x = factor(subset), y = agree,
                                                          fill = factor(sample))) +
  geom_violin(adjust = 1.3) +
  stat_summary(fun = mean, geom = "errorbar", aes(ymax = ..y.., ymin = ..y..),
               width = 1, linetype = "solid") +
  scale_x_discrete(breaks = c("1", "0"),
                   labels = c("active\nPutin opponents", 
                              "non-active\nPutin supporters")) +
  scale_fill_manual(values = c("grey90")) +
  xlab("") +
  ylab("agreeableness") +
  theme_bw() +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5)); p.H3desc_ag

# fuse graphs to vreate Figure D1
ggsave("Figure_D1b.pdf", gridExtra::grid.arrange(p.H3desc_ex, p.H3desc_ag, ncol = 2, nrow = 1,
                                             top = "extraversion and agreeableness in groups B and C of 2013 survey"),
       width = 8, height = 4)

##### Supplementary Appendix E: conflicts in family #####

# Table E1: Navalny activists and conflict

conflicts <- data2 %>%
  filter(navact==1) %>%
  select(confl_w_rel, confl_w_friends, confl_at_work, confl_other)

sapply(conflicts, function (x) {prop.table(table(x))})  %>% round(., 3)

conflicts_all <- ifelse(data2$confl_w_rel==2 | data2$confl_w_friends==2 | 
                          data2$confl_at_work==2 | data2$confl_other==2,1,0)
prop.table(table(conflicts_all)) %>% round(., 3)


##### Supplementary Appendix F: fear to engage #####

# bivariate associations with extraversion
aggregate(data1$extra, by = list(data1$polfear), FUN = mean)

### Table F1

# OLS models
m.polfear1 <- lm(polfear ~ extraST, data = data1)

# adding controls
m.polfear2 <- lm(polfear ~ extraST + age + edu + female + wealth + moscow, 
                 data = data1)

tab_model(m.polfear1, m.polfear2,
          show.se = TRUE, show.ci = FALSE, 
          p.style = "stars", collapse.se = TRUE, show.ci50 = TRUE, 
          dv.labels = c(rep.int("fear to engage", 4)),
          file = "Table_F1.html")

##### Supplementary Appendix L: Political attitudes among oppositionists #####

### Figure L1a

data1 %>%
  filter(putin_sup==0) %>%
  group_by(minorities) %>%
  dplyr::summarise(n = n()) %>%
  filter(minorities!="NA") %>%
  ggplot(., aes(x = factor(minorities), y = n)) +
  geom_bar(stat = "identity") +
  xlab("Protecting minorites") +
  ylab("") +
  scale_x_discrete(breaks = c("1", "2", "3", "4", "5"),
                   labels = c("very\nimportant", "rather\nimportant", "neutral",
                              "rather not\nimportant", "not at all\nimportant")) +
  theme_bw()

ggsave("Figure_L1a.pdf", height = 4, width = 4)


data1 %>%
  filter(putin_sup==0) %>%
  group_by(equalpay) %>%
  dplyr::summarise(n = n()) %>%
  filter(equalpay!="NA") %>%
  ggplot(., aes(x = factor(equalpay), y = n)) +
  geom_bar(stat = "identity") +
  xlab("Equal distribution of incomes") +
  ylab("") +
  scale_x_discrete(breaks = c("1", "2", "3", "4", "5"),
                   labels = c("very\nimportant", "rather\nimportant", "neutral",
                              "rather not\nimportant", "not at all\nimportant")) +
  theme_bw()

ggsave("Figure_L1b.pdf", height = 4, width = 4)


### Table L1 and additional t-tests and correlations in appendix L

# subset opposition for high and low values on attitudinal questions
data1_minhigh <- data1 %>%
  filter(!(putin_sup==0 & minorities>=3))
data1_minlow <- data1 %>%
  filter(!(putin_sup==0 & minorities<=3))

data1_equalhigh <- data1 %>%
  filter(!(putin_sup==0 & equalpay>=3))
data1_equallow <- data1 %>%
  filter(!(putin_sup==0 & equalpay<=3))

### t-tests
#base line
t.test(extra ~ subset, data = data1)
t.test(agree ~ subset, data = data1)

# minorities
t.test(extra ~ subset, data = data1_minhigh)
t.test(agree ~ subset, data = data1_minhigh)

t.test(extra ~ subset, data = data1_minlow)
t.test(agree ~ subset, data = data1_minlow)

# equal pay
t.test(extra ~ subset, data = data1_equalhigh)
t.test(agree ~ subset, data = data1_equalhigh)

t.test(extra ~ subset, data = data1_equallow)
t.test(agree ~ subset, data = data1_equallow)

### correlations
cor.test(1-data1$minorities[data1$subset==1], 
         data1$extra[data1$subset==1], method = "pearson")
cor.test(1-data1$minorities[data1$subset==1], 
         data1$agree[data1$subset==1], method = "pearson")

cor.test(1-data1$equalpay[data1$subset==1], 
         data1$extra[data1$subset==1], method = "pearson")
cor.test(1-data1$equalpay[data1$subset==1], 
         data1$agree[data1$subset==1], method = "pearson")

### subset opposition for Zyuganov and Navalny support
data1_Zyug <- data1 %>%
  filter(!(putin_sup==0 & putin_sup_raw!=3))
data1_Nav <- data1 %>%
  filter(!(putin_sup==0 & putin_sup_raw!=6))

### t-tests
#base line
t.test(extra ~ subset, data = data1)
t.test(agree ~ subset, data = data1)

# Zyuganov
t.test(extra ~ subset, data = data1_Zyug)
t.test(agree ~ subset, data = data1_Zyug)

# Navalny
t.test(extra ~ subset, data = data1_Nav)
t.test(agree ~ subset, data = data1_Nav)


##### Supplementary Appendix O: Sample size calculation #####

# set parameters
alpha <- 0.05
power <- 0.8
p0ex <- predictH3a_ex$predicted[2] # predicted probability for extraversion at mean (full case control model of 2013 data)
p1ex <- predictH3a_ex$predicted[3] # predicted probability for extraversion at mean+1sd (full case control model of 2013 data)
p0ag <- predictH3a_ag$predicted[2] # predicted probability for agreeableness at mean (full case control model of 2013 data)
p1ag <- predictH3a_ag$predicted[3] # predicted probability for agreeableness at mean+1sd (full case control model of 2013 data)

# odds ratios
OR_ex <- (p1ex/(1-p1ex))/(p0ex/(1-p0ex))
OR_ag <- (p1ag/(1-p1ag))/(p0ag/(1-p0ag))

# calculate R2 of extra and agree as DV (to use in G*Power)

m.power_ex <- lm(extraST ~ openST + conscST  + agreeST + neurST +
                   age + edu + female + wealth + moscow,
                 data = data1)
summary(m.power_ex)$r.squared

m.power_ag <- lm(agreeST ~ openST + conscST  + extraST + neurST +
                   age + edu + female + wealth + moscow,
                 data = data1)
summary(m.power_ag)$r.squared

### EXTERNALlY calculate sample size in G*Power with p1, OR, and R-2, then output table
### tables are attached here

# graph the output from G*Power
extra_n <- fread("sample_size_extraversion.csv")
agree_n <- fread("sample_size_agreeableness.csv")

ggplot(extra_n, aes(x = power, y = n)) +
  geom_line() +
  geom_point(size = 1,
             fill = "white",
             colour = "black",
             shape = 21) +
  xlab("power") +
  ylab("sample size") +
  ggtitle("extraversion") +
  theme_bw()

ggsave("Figure_O1a.pdf", width = 7, height = 3)

ggplot(agree_n, aes(x = power, y = n)) +
  geom_line() +
  geom_point(size = 1,
             fill = "white",
             colour = "black",
             shape = 21) +
  xlab("power") +
  ylab("sample size") +
  ggtitle("agreeableness") +
  theme_bw()

ggsave("Figure_O1b.pdf", width = 7, height = 3)


